package com.handpay.nocardpay.baselibrary.main.all.view.widget;

import android.content.Context;
import android.text.TextUtils;

import com.handpay.nocardpay.baselibrary.R;
import com.handpay.nocardpay.baselibrary.db.ormlite.DataBaseComponentModel;
import com.handpay.nocardpay.baselibrary.main.all.model.bean.component.ComponentItemBean;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * 主界面显示的组建
 *
 * @author dlfeng
 *         2015/5/14
 */
public class FunctionInfo {
    //        <ITEM_TITLE>在线商城</ITEM_TITLE>
    public static final String HONG_SHOP_ICON_CODE = "hong_shop";
    public static final String INTRE_PAYMENT_ICON_CODE = "intre_payment";
    public static final String LOAN_ICON_CODE = "loan_dai";


    //        <ITEM_TITLE>智能还款</ITEM_TITLE>
    public static final String HONG_SHOP_CODE = "onlineMarket";
    public static final String INTRE_PAYMENT_CODE = "intrePayment";
    public static final String LOAN_CODE = "loan";

    // 小雨滴网贷
    public static final String DFPAY_ICON_NNAME = "xiao_yu_dian";
    public static final String DFPAY_ITEM_CODE = "smallRainPoint";


    /*
    0、1、收款        	    CollectMoney
    1、2、快速转账      	FastTransfer
    2、3、信用卡还款	RepaymentCreditcard
    3、4、用户通知		UserNotice
    4、5、话费充值		PrepaidRecharge
    5、6、游戏充值		GameRecharge
    6、7、基本信息		BasicInfo
    7、8、资质信息		QualificationInfo
    8、9、收款卡管理	CollectCardManagement
    9、10、收款限额	CollectLimit
    10、11、收款流水	CollectFlow
    11、12、收款提现	CollectWithdraw
    12、13、刷卡器连接	SwipeSelect
    13、14、微理财                 SmallFinancing
    14、15、Q币充值              QBRecharge
    15、16,TO资质提现      T0Qualification
    16、17,TO卡小宝二维码界面      KXBScanner
    21、股票开户
    22、扫码收款
    23、代还信用卡
    24、贷款
    25、全部应用
    */
//    public static final String[] FUNCTIONID = new String[]{
//            "collectmoney",//0
//            "fasttransfer",//1
//            "repaymentcreditcard",//2
//            "usernotice",//3
//            "prepaidrecharge",//4
//            "gameRecharge",//5
//            "basicinfo",//6
//            "qualificationinfo",//7
//            "collectcardmanagement",//8
//            "collectlimit",//9
//            "collectflow",//10
//            "collectwithdraw",//11
//            "swipeselect",//12
//            "smallfinancing",//13
//            "QBRecharge",//14
//            "T0Qualification",//15
//            "QQConsultation",//16
//            "KXBScanner",//卡小宝17
//            "Shop98",//18
//            "DistributionSystem",//0
//            "IDCardate",//0
//            "OpenAcountAOP",//股票开户
//            "ScannerCodePay",//扫码收款
//            "LoanCreditCard",//代还信用卡
//            "Loan",//贷款
//            "JieAn",//捷安借贷
//            "AllFunction",//全部应用
//    };


    //    public static final String[] FUNCTIONTITLE = new String[]{
//            "刷卡收款",
//            "银联转账",
//            "信用卡还款",
//            "用户通知",
//            "话费充值",
//            "游戏充值",
//            "基本信息",
//            "资质信息",
//            "收款卡管理",
//            "收款限额",
//            "收款流水",
//            "收款提现",
//            "刷卡器连接",
//            "微理财",
//            "Q币充值",
//            "提现资质",
//            "在线咨询",
//            "卡小宝",
//            "98商城",
//            "在线商城",
//            "证件补传",
//            "证券开户",
//            "扫码支付",
//            "代还信用卡",
//            "贷款",
//            "捷安借贷",
//            "全部应用"
//
//    };
//    public static final Class<?>[] FUNCTIONCLS = new Class<?>[]{
//            MainActivity.class,
//            SuperTransferAccounts.class,
//            SuperTransferAccounts.class,
//            NoticeActivity.class,
//            ShowHtmlActivity.class,
//            ShowHtmlActivity.class,
//            BaseInfoActivity.class,
//            QualificationInfoActivity.class,
//            BankCardManagerActivity.class,
//            TransferCashLimitManagementActivity.class,
//            QueryBillsActivity.class,
//            WithdrawActivity.class,
//            ConnectSwiperActivity.class,
//            FinancingAreaActivity.class,
//            ShowHtmlActivity.class,
//            T0QualificationActivity.class,
//            ShowHtmlActivity.class,
//            KxbActivity.class,
//            ShowHtmlActivity.class,
//            ShowMarketHtmlActivity.class,
//            IDCardateActivity.class,
//            ShowHtmlActivity.class,
//            ScannerCodePayActivity.class,
//            ShowLoanHtmlActivity.class,
//            ShowHtmlActivity.class,
//            JieAnHtmlActivity.class,
//            AllFunctionActivity.class,
//    };
    public String itemId;
    public String title;
    public int[] iconResId;
    public String iconUrl;


    public int index;
    public int showModule;
    public String type;


    public FunctionInfo(String itemId, String title, int[] iconResId, String type) {
        super();
        this.itemId = itemId;
        this.title = title;
        this.iconResId = iconResId;
        this.type = type;
    }


    public static int getDrawableResIdByItemCode(String itemCode) {
        if (itemCode.equals(HONG_SHOP_CODE)) {
            //在线商城
            return R.drawable.home_icon_market;
        } else if (itemCode.equals(INTRE_PAYMENT_CODE)) {
            //智能还款
            return R.drawable.home_icon_intre_payment;
        } else if (itemCode.equals(LOAN_CODE)) {
            //贷款
            return R.drawable.home_icon_loan;
        } else if (itemCode.equals(DFPAY_ITEM_CODE)) {
            return R.drawable.home_icon_yudian;
        } else {
            return R.drawable.home_icon_market;
        }
    }

    public static int getDrawableResIdByFunctionIconName(String iconName, String itemCode) {
        if (iconName.equals(HONG_SHOP_ICON_CODE)) {
            //在线商城
            return R.drawable.home_icon_market;
        } else if (iconName.equals(INTRE_PAYMENT_ICON_CODE)) {
            //智能还款
            return R.drawable.home_icon_intre_payment;
        } else if (iconName.equals(LOAN_ICON_CODE)) {
            //贷款
            return R.drawable.home_icon_loan;
        } else if (iconName.equals(DFPAY_ICON_NNAME)) {
            return R.drawable.home_icon_yudian;
        } else {
            return getDrawableResIdByItemCode(itemCode);
        }
    }

    public static Class<?> getClazzByItemCode(String itemCode) {
//        if (itemCode.equals(COLLECT_MONEY_CODE)) {
//            //刷卡收款
//            return MainActivity.class;
//        } else if (itemCode.equals(SCAN_PAYMENT_CODE)) {
//            //扫码支付
//            return ScannerCodePayActivity.class;
//        } else if (itemCode.equals(QR_CODE_CODE)) {
//            //码上付
//            return ScannerCodePayActivity.class;
//        } else if (itemCode.equals(MONG_HOO_CODE)) {
//            //代换信用卡
//            return ShowLoanHtmlActivity.class;
//        } else if (itemCode.equals(HONG_SHOP_CODE)) {
//            //在线商城
//            return ShowMarketHtmlActivity.class;
//        } else if (itemCode.equals(LOAN_PACKAGE_ICON_CODE)) {
//            return null;
//        } else if (itemCode.equals(STOCK_FUND_CODE)) {
//            //证券开户
//            return ShowHtmlActivity.class;
//        } else if (itemCode.equals(QQ_IM_CODE)) {
//            return AllFunctionActivity.class;
//        } else if (itemCode.equals(GATHER_APP_CODE)) {
//            return AllFunctionActivity.class;
//        } else if (itemCode.equals(JIEAN_CODE)) {
//            return JieAnHtmlActivity.class;
//        } else if (itemCode.equals(MOBILE_RECHARGE_CODE)) {
//            return ShowHtmlActivity.class;
//        } else if (itemCode.equals(NO_CARD_PAYMENT_CODE)) {
//            return ShowHtmlActivity.class;
//        } else if (itemCode.equals(LOAN_CODE)) {
//            return ShowHtmlActivity.class;
//        } else if (itemCode.equals(FAST_TRANSFER_CODE)) {
//            return SuperTransferAccounts.class;
//        } else if (itemCode.equals(CREDIT_CARD_CODE)) {
//            return SuperTransferAccounts.class;
//        } else if (itemCode.equals(INTRE_PAYMENT_CODE)) {
//            return IntrePaymentHtmlActivity.class;
//        }
//        return AllFunctionActivity.class;
        return null;
    }

    public static boolean isExistComponent(String itemCode) {
        if (itemCode.equals(HONG_SHOP_CODE)) {
            //在线商城
            return true;
        } else if (itemCode.equals(INTRE_PAYMENT_CODE)) {
            //智能还款
            return true;
        } else if (itemCode.equals(LOAN_CODE)) {
            //贷款
            return true;
        } else if (itemCode.equals(DFPAY_ITEM_CODE)) {
            return true;
        }
        return false;
    }

    @Override
    public String toString() {
        return "FunctionInfo{" +
                "itemId='" + itemId + '\'' +
                ", title='" + title + '\'' +
                ", iconResId=" + Arrays.toString(iconResId) +
                ", iconUrl='" + iconUrl + '\'' +
                ", index=" + index +
                ", showModule=" + showModule +
                ", type='" + type + '\'' +
                '}';
    }

    public static HashMap<String, FunctionInfo> getFunctionInfos(Context context) {
        DataBaseComponentModel dbModel = new DataBaseComponentModel(context);
        List<ComponentItemBean> list = dbModel.queryComponentList();
        HashMap<String, FunctionInfo> map = new HashMap<String, FunctionInfo>();
        for (ComponentItemBean component : list) {
            String functionID = component.getItemCode();
            if (TextUtils.isEmpty(functionID)) {
                continue;
            }
            String functionTitle = component.getItemTitle();
            String functionIconName = component.getIconName();
            String functionType = component.getItemType();
            int functionIconResId = getDrawableResIdByFunctionIconName(functionIconName, functionID);
//            Class<?> functionClazz = getClazzByItemCode(functionID);
            map.put(functionID, new FunctionInfo(functionID, functionTitle, new int[]{functionIconResId}, functionType));
        }
        return map;
    }
}
